//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';

/// 选择考试标签显示
class ExamLabelWidget extends StatelessWidget {
  /// 显示字体
  final String text;

  /// 宽度
  final double width;

  /// 是否是选择考试的标签
  final bool exam;

  /// 是否显示已购买
  final bool showBuy;

  const ExamLabelWidget({
    super.key,
    required this.text,
    required this.width,
    required this.exam,
    this.showBuy = false,
  });

  ExamLabelWidget.exam({
    super.key,
    required this.text,
  })  : width = 249,
        exam = true,
        showBuy = false;

  ExamLabelWidget.category({
    super.key,
    required this.text,
    required this.showBuy,
  })  : width = 213,
        exam = false;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      height: 72,
      child: Stack(
        children: [
          Positioned.fill(child: _labelItem()),
          if (showBuy)
            Positioned(
              child: _buyLabelItem(),
              top: 0,
              right: 1,
            )
        ],
      ),
    );
  }

  /// 标签主体
  _labelItem() {
    return Container(
      width: width,
      height: 72,
      padding: EdgeInsets.symmetric(vertical: 2, horizontal: 10),
      decoration: BoxDecoration(
        color: exam ? colorBlue2 : colorWhite2,
        borderRadius: BorderRadius.all(Radius.circular(18)),
      ),
      child: Center(
        child: Text(
          text,
          style: exam ? FontUtil.fontBlue1(12) : FontUtil.fontBlack1(12),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
      ),
    )
        .animate().fadeIn()
    ;
  }

  /// 已购买标签
  _buyLabelItem() {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 2, horizontal: 6),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
          topRight: Radius.circular(18),
          bottomLeft: Radius.circular(18),
        ),
        border: Border.all(color: colorBlue1, width: 1),
      ),
      child: Text(
        "已购",
        style: FontUtil.fontBlue1(18),
      ),
    );
  }
}
